package com.dru.drutils.media;

import android.content.Context;
import android.content.res.TypedArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.dru.drutils.R;

public class ImageAdapter extends BaseAdapter {
    protected int mGalleryItemBackground 	= 0;
    protected Context mContext;
    protected int width 					= 150;
    protected int height					= 100;
    
    protected Integer[] mImageIds = {
            R.drawable.ic_launcher,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher
    };

    public ImageAdapter(Context c) {
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.Gallery);
        mGalleryItemBackground = attr.getResourceId( R.styleable.Gallery_galleryItemBackground, 0 );
        attr.recycle();
    }
    
    public ImageAdapter(Context c, int width, int height ) {
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.Gallery);
        mGalleryItemBackground = attr.getResourceId( R.styleable.Gallery_galleryItemBackground, 0 );
        this.width = width;
        this.height = height;
        attr.recycle();
    }

    public int getCount() {
        return mImageIds.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public void setWidth( int width )
    {
    	this.width = width;
    }
    
    public void setHeight( int height )
    {
    	this.height = height;
    }
    
    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView( mContext );

        imageView.setImageResource( mImageIds[position] );
        imageView.setLayoutParams( new Gallery.LayoutParams( Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT ) );
        imageView.setScaleType( ImageView.ScaleType.CENTER );
        imageView.setBackgroundResource( mGalleryItemBackground );

        return imageView;
    }
    
    public void setResIds ( Integer[] ids )
    {
    	this.mImageIds = ids;
    }
    
    //public void setBitmaps()
}